package cn.evilelf.util;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.util.Scanner;

/**
 * RemoveLine实用工具用于将用换行wrap过的文本（如小百合的帖子）进行还原，目前不能保证完美输出
 * @author xmx
 */
public class RemoveLine {
	
	static String wordsplit="";
	
	/**
	 * @param inFile	输入文本文件
	 * @param outFile	输出文本文件
	 * @param inEncode	输入文本文件的编码
	 * @param outEncode	输出文本文件的编码
	 * @throws FileNotFoundException
	 * @throws UnsupportedEncodingException
	 */
	public static void remove(File inFile, File outFile, String inEncode, String outEncode) throws FileNotFoundException, UnsupportedEncodingException {
		Scanner in = new Scanner(inFile, inEncode);
		PrintWriter out = new PrintWriter(outFile, outEncode);
		while (in.hasNextLine()) {
			String line = in.nextLine().trim();
			if ("".equals(line))	//空行，新的一段
				out.println();
			else {
				out.print(line + wordsplit);
				System.out.println(line);
			}
		}
		out.flush(); // important!
	}
}
